package com.zjt.swipeview.component.footer;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;

import com.zjt.swipeview.R;
import com.zjt.swipeview.event.OnLoadStateChangeListener;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2017</p>
 * <P>Company: </p>
 *
 * @author zhengjianting
 * @time 2017/11/23 0023 下午 4:45
 */

public class AutoLoadMoreFooter extends FrameLayout implements OnLoadStateChangeListener{

    private View loadingView;
    private View loadFinishView;
    private View loadFailView;

    public AutoLoadMoreFooter(Context context) {
        super(context);
    }

    public AutoLoadMoreFooter(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public AutoLoadMoreFooter(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public AutoLoadMoreFooter(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        initChildView();
    }

    private void initChildView() {
        loadingView = LayoutInflater.from(getContext())
                .inflate(R.layout.footer_state_loading, this, false);
        loadingView.setVisibility(View.VISIBLE);

        loadFinishView = LayoutInflater.from(getContext())
                .inflate(R.layout.footer_state_load_finish, this, false);
        loadFinishView.setVisibility(GONE);

        loadFailView = LayoutInflater.from(getContext())
                .inflate(R.layout.footer_state_load_fail, this, false);
        loadFailView.setVisibility(View.GONE);

        addView(loadingView);
        addView(loadFinishView);
        addView(loadFailView);
    }

    @Override
    public void onLoading() {
        loadingView.setVisibility(VISIBLE);
        loadFinishView.setVisibility(GONE);
        loadFailView.setVisibility(GONE);
    }

    @Override
    public void onLoadFinish() {
        loadingView.setVisibility(GONE);
        loadFinishView.setVisibility(VISIBLE);
        loadFailView.setVisibility(GONE);
    }

    @Override
    public void onLoadFail() {
        loadingView.setVisibility(GONE);
        loadFinishView.setVisibility(GONE);
        loadFailView.setVisibility(VISIBLE);
    }
}
